package sz.szsmk.citizencard.ui.dzsmkavtivity;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.gyf.immersionbar.ImmersionBar;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.dzbean.res.Qa;
import sz.szsmk.citizencard.mvp.BasePresenter;
import sz.szsmk.citizencard.mvp.FAQMvpView;
import sz.szsmk.citizencard.mvp.dzsmkpresenter.FAQPresenter;

import java.util.List;

import javax.inject.Inject;


/**
 * Created by yangzhengwen on 2017/10/5.
 */

public class FAQActivity extends AppBaseActivity implements FAQMvpView {

    RecyclerView rv_qr_list;

    @Inject
    FAQPresenter faqPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getComponent().inject(this);
        setContentView(R.layout.qr_activity_recyclerview);

        rv_qr_list = findViewById(R.id.rv_qr_list);

        ImmersionBar.with(this)
                .fitsSystemWindows(true)
                .statusBarDarkFont(true, 0f)
                .statusBarColor(R.color.white).init();
        faqPresenter.getFAQ();
    }

    @Override
    protected BasePresenter[] initPresenters() {
        return new BasePresenter[]{faqPresenter};
    }

    @Override
    public void onGetQASuccess(final List<Qa> list) {
        rv_qr_list.setLayoutManager(new LinearLayoutManager(FAQActivity.this));
        BaseQuickAdapter bankAdapter = new BaseQuickAdapter<Qa, BaseViewHolder>(R.layout.qr_item_faq, list) {

            @Override
            protected void convert(BaseViewHolder helper, Qa item) {
                helper.setText(R.id.tv_qr_title, item.getTitle());
            }
        };
        bankAdapter.openLoadAnimation();
        rv_qr_list.setAdapter(bankAdapter);

        bankAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Qa faq = list.get(position);
                Intent intent = new Intent(FAQActivity.this, QuestionDetailActivity.class);
                intent.putExtra("faq", faq);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onGetQAFail() {

    }

    @Override
    protected CharSequence getTopTitle() {
        return "常见问题";
    }
}
